{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas\n",
    "import json \n",
    "\n",
    "import jupynbimp\n",
    "import restaurants_data_cleaning "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def getReviews():\n",
    "        \n",
    "    dataDirectory = '../../data/yelp/'\n",
    "    restaurants = restaurants_data_cleaning.getData(fromCache=True)\n",
    "    \n",
    "    # read-in .json file as pandas dataframe\n",
    "    reviews = (pandas.DataFrame.from_dict([\n",
    "                json.loads(data) for data in open(\n",
    "                    dataDirectory + 'yelp_academic_dataset_review.json', 'r')\n",
    "            ]))\n",
    "        \n",
    "    # keep only reviews from selected restaurants\n",
    "    reviews = (reviews[reviews['business_id']\n",
    "                       .isin(restaurants['business_id'])\n",
    "                      ]\n",
    "               .drop(['type', 'user_id', 'votes'], axis = 1)\n",
    "              )\n",
    "\n",
    "    reviews['date'] = pandas.to_datetime(reviews['date'])\n",
    "    \n",
    "    return reviews"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
